package dao.impl;

import dao.CaseHistoryDao;
import entity.CaseHistory;
import util.CaseHistoryRowMapper;
import util.DruidUtils;

import java.util.List;

/**
 * @Author:
 * @Date: 2020-04-22
 * @Description: @PACKAGE:dao.impl
 * @version: 1.0
 */
public class CaseHistoryDaoImpl implements CaseHistoryDao {

    @Override
    public List<CaseHistory> getAllCaseHistory() {
        String sql="select * from t_casehistory";
        List<CaseHistory> list = DruidUtils.commonsSelect(sql,new CaseHistoryRowMapper(),new Object[]{});
        return list;
    }

    @Override
    public List<CaseHistory> getByCaseHistoryId(String id) {
        String sql="select * from t_casehistory where ch_number ='"+id+"'";
        List<CaseHistory> list = DruidUtils.commonsSelect(sql,new CaseHistoryRowMapper(),new Object[]{});
        return list;
    }

    @Override
    public List<CaseHistory> getByDoctorId(String id) {
        String sql="select * from t_casehistory where ch_doctorid ='"+id+"'";
        List<CaseHistory> list = DruidUtils.commonsSelect(sql,new CaseHistoryRowMapper(),new Object[]{});
        return list;
    }

    @Override
    public List<CaseHistory> getByPatientId(String id) {
        String sql="select * from t_casehistory where ch_patientid ='"+id+"'";
        List<CaseHistory> list = DruidUtils.commonsSelect(sql,new CaseHistoryRowMapper(),new Object[]{});
        return list;
    }

    @Override
    public List<CaseHistory> getByCaseHistoryIdLike(String id) {
        String sql="select * from t_casehistory where ch_number like '"+id+"%'";
        List<CaseHistory> list = DruidUtils.commonsSelect(sql,new CaseHistoryRowMapper(),new Object[]{});
        return list;
    }

    @Override
    public List<CaseHistory> getByPatientIdOrderByDate(String id) {
        String sql="select * from t_casehistory where ch_patientid ='"+id+"' order by ch_date";
        List<CaseHistory> list = DruidUtils.commonsSelect(sql,new CaseHistoryRowMapper(),new Object[]{});
        return list;
    }

    @Override
    public int add(CaseHistory caseHistory) {
        String sql = "insert  into `t_casehistory`(`ch_number`,`ch_date`,`ch_updateDate`,`ch_doctorid`,`ch_patientid`,`ch_symptom`,`ch_checkitem`,`ch_result`,`ch_clinicaldiagnosis`,`ch_plan`,`ch_druglist`,`ch_advice`,`ch_Degree_symptoms`) values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
        //String sql = "insert  into `t_doctor`(`id`) values (?)";
        int i = DruidUtils.executeUpdate(sql, caseHistory.getCh_number(), caseHistory.getCh_date(), caseHistory.getCh_updateDate(),
                caseHistory.getCh_doctorid(), caseHistory.getCh_patientid(), caseHistory.getCh_symptom(),
                caseHistory.getCh_checkitem(), caseHistory.getCh_result(), caseHistory.getCh_clinicaldiagnosis(),
                caseHistory.getCh_plan(), caseHistory.getCh_druglist(), caseHistory.getCh_advice(), caseHistory.getCh_Degree_symptoms());

        return i;
    }

    @Override
    public int delete(String caseHistoryNo) {
        String sql = "delete from t_casehistory where ch_number = ?";
        int i = DruidUtils.executeUpdate(sql,caseHistoryNo);

        return i;
    }

    @Override
    public int update(CaseHistory caseHistory) {
        String sql = "update t_casehistory set `ch_updateDate`=?," +
                "`ch_doctorid`=?,`ch_patientid`=?,`ch_symptom`=?," +
                "`ch_checkitem`=?,`ch_result`=?,`ch_clinicaldiagnosis`=?," +
                "`ch_plan`=?,`ch_druglist`=?,`ch_advice`=?," +
                "`ch_Degree_symptoms`=? where `ch_number`=?";
        //String sql = "insert  into `t_doctor`(`id`) values (?)";
        int i = DruidUtils.executeUpdate(sql, caseHistory.getCh_updateDate(), caseHistory.getCh_doctorid(),
                caseHistory.getCh_patientid(), caseHistory.getCh_symptom(), caseHistory.getCh_checkitem(),
                caseHistory.getCh_result(), caseHistory.getCh_clinicaldiagnosis(), caseHistory.getCh_plan(),
                caseHistory.getCh_druglist(), caseHistory.getCh_advice(), caseHistory.getCh_Degree_symptoms(), caseHistory.getCh_number());

        return i;
    }
}